$(function () {

    $("a").on("click", function () {
        var methods = $(this).data("method");
        if(methods){
            itsource[methods]();
        }
    });

    $("#sell").switchbutton({
        onChange:function(v){
            /*document.getElementById("hide").style.display = "block";*/
            /*document.getElementById('sellanalysis').hide();*/
            if(v===true){
                /*console.debug(v);*/
                $("#sellanalysis").show();
            }else {
                $("#sellanalysis").hide();
            }
        }
    })

    $('#dd').panel({
       /* href:'content_url.php',*/
        onLoad:function(){
            alert('loaded successfully');
        }
    });

    var span =  $("#span");

    var itsource={
        '1':function () {
            alert(1)
        },
        '2':function () {
            alert(2)
        },
        '3':function () {
            alert(3)
        },
        'day':function () {
            document.getElementById('span').innerHTML='今日';
            chart(1)
        },
        'week':function () {
            document.getElementById('span').innerHTML='本周';
            chart(7);
        },
        'yue':function () {
            document.getElementById('span').innerHTML='本月';
            chart(30);
        },
        'RingChart':function () {
            /*alert('RingChart')*/
            RingChart();
        },
        'dlog':function () {
            $("#dd").dialog("open");
        }
    }


  /*  var series= [];
    for(var i=0;i<set.length;i++){
        var data = [];
        for(var j=0;j<list.length;j++){
            if(map[list[j]+"_"+set[i]] != undefined){//map 后台传输到前台的map
                data.push(map[list[j]+"_"+set[i]]);
            }else{
                data.push(0);
            }
        }
        var serie ={
            name:set[i],
            data:data
        }
        series.push(serie);
    }

    字符串转时间格式
    console.debug(data.listSum);
            var s = "2005-12-15 09:41:30";
           /* var d = new Date(Date.parse(s.replace(/-/g, "/")));
    /*data.oldYueDate*/
    /*console.debug(d);
    var arr=[];
    $.each(data.oldYueDate,function (i,o) {
        var d = new Date(Date.parse(o.replace(/-/g)));
        arr.push(d);
        console.debug(d)
    })
*/
    function chart(term) {
        //alert(term)
        $.get("storeOverview/selectReportByTerm",{"term":term},function (data) {

            var chart = Highcharts.chart('container', {

                title: {
                    text: ''
                },
                //水印
                credits: {
                    enabled: false
                },
                //去除图标
                exporting: {
                    enabled:false
                },
                yAxis: {
                    title: {
                        text: '金额'
                    },
                    lineWidth:1,
                    tickPositions: [0,10,20, 30,50,100,150,200]
                },
                xAxis: {
                    categories:data.oldYueDate
                },

                legend: {
                    /*layout: 'vertical',*/
                    align: 'right',
                    verticalAlign: 'middle'
                },
                series: [{
                    name: '销售员甲',
                    data: data.listSum,

                }]/*,字符串不能写这个，冲突
                plotOptions: {
                    series: {
                        label: {
                            connectorAllowed: false
                        },
                        pointStart: 2010
                    }
                }*/
            });
        })
    }


    function RingChart() {
        $.get("storeOverview/selectRingChart",function (data) {

           console.debug("111"+data.oldYueDate)
            var chart = Highcharts.chart('RingChart', {
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false
                },
                //水印
                credits: {
                    enabled: false
                },
                //去除图标
                exporting: {
                    enabled:false
                },
                title: {
                    text: '会员<br>比例',
                    align: 'center',
                    verticalAlign: 'middle',
                    y: -40
                },
                tooltip: {
                    /*11.tooltip: {
        12.shared: true, //是否共享提示，也就是X一样的所有点都显示出来
        13.useHTML: true, //是否使用HTML编辑提示信息
        14.headerFormat: '<small>{point.key}</small><table>',
        15.pointFormat: '<tr><td style="color: {series.color}">{series.name}: </td>' +
        16.'<td style="text-align: right"><b>{point.y}</b></td></tr>',
        17.footerFormat: '</table>',
        18.valueDecimals: 2 //数据值保留小数位数
        19.},*/
                    shared: true,
                    useHTML: true,
                    headerFormat: '{series.name}<br>',
                    pointFormat: '{point.name}: <b>{point.percentage:.1f}%</b>',
                    footerFormat: '</table>',
                    valueDecimals: 2
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        showInLegend: true,
                        innerSize: '30%',
                        dataLabels: {
                            //enabled: false,//是否显示文字
                            enabled: false,
                            distance: 250,
                            /* style: {
                                 //fontWeight: 'bold',
                                 //color: 'white',
                                 //textShadow: '0px 1px 2px black'
                             }*/
                        },
                        startAngle: -270, // 圆环的开始角度
                        endAngle: 90,    // 圆环的结束角度
                        center: ['50%', '44%']
                    }
                },
                legend:{
                    align: 'center', //水平方向位置
                    symbolWidth:50,
                    symbolHeigth:16,
                    symbolRadius:0,
                    itemStyle:{
                        lineHeigth:'20px',
                        fontSize:'20px',
                        letterSpacing:0,
                        color:'#666666',
                        fontWidth:'lighter'
                    },
                    verticalAlign: 'bottom', //垂直方向位置
                    x: 0, //距离x轴的距离
                    y: 0,//距离Y轴的距离
                    labelFormatter:function () {
                        /*Highcharts.numberFormat(this.percentage, x)*/
                        return this.name + '(' +Highcharts.numberFormat(this.percentage, 3) +'%)';
                    }
                },

                series: [{
                    type: 'pie',
                    name: '浏览器占比',
                    innerSize: '50%',
                    data:data.oldYueDate
                    /* [
                        /!*['Firefox',   45.0],
                        ['IE',       26.8],
                        ['Chrome', 12.8],
                        ['Safari',    8.5],
                        ['Opera',     6.2],*!/
                        {
                            name: '其他',
                            y: 0.7
                            /!*dataLabels: {
                                // 数据比较少，没有空间显示数据标签，所以将其关闭
                                enabled: false
                            }*!/
                        },
                        {
                            name: '其2',
                            y: 0.7
                            /!*dataLabels: {
                                // 数据比较少，没有空间显示数据标签，所以将其关闭
                                enabled: false
                            }*!/
                        }
                    ]*/
                }]
            });
        })
    }

    onLoadSuccess:{
        itsource['week']();
        itsource['RingChart']();
    }
})

